<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="btn">测试ajax封装</button>
  <script>


    document.getElementById('btn').onclick = async () => {
      // const p = ajax('http://localhost:3000/movie2?q=飞')
      // p.then(
      //   result => console.log('请求成功的数据', result),
      //   error => alert(error.message)
      // )
      try {
        const result = await ajax('http://localhost:3000/movie2?q=飞')
        console.log('请求成功的数据2', result)
      } catch (error) {
        alert(error.message)
      }
    }

    async function request() {
      const result = await ajax('http://localhost:3000/movie2?q=飞')
      return result
    }

    async function test() {

      const result = await {m: 1}
      console.log('result', result)

      
      const promise = request()
      console.log(promise)
    }
    test()
   
  </script>
</body>
</html>